package com.btks.water3d;

import androidx.appcompat.app.AppCompatActivity;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Context;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.VideoView;

import com.supermap.data.Environment;
import com.supermap.data.LicenseStatus;
import com.supermap.data.Workspace;
import com.supermap.data.WorkspaceConnectionInfo;
import com.supermap.data.WorkspaceType;
import com.supermap.realspace.Scene;
import com.supermap.realspace.SceneControl;

import java.io.File;
import java.util.Timer;
import java.util.TimerTask;

import pub.devrel.easypermissions.EasyPermissions;

public class MapAcitivty extends BaseActivity {
    private final String TAG = "debug";
    private Context context;

    private final String EXPLAIN_ALL_MP4_PATH = "/sdcard/SuperMap/video/介绍.mp4";
    private final String SIMULATE_ANIM_1 = "/sdcard/SuperMap/video/双闸动画.mp4";
    private final String SIMULATE_ANIM_2 = "/sdcard/SuperMap/video/单闸动画.mp4";
    private final String SIMULATE_ANIM_3 = "/sdcard/SuperMap/video/管道流水动画.mp4";


    private Button btn_play, btn_pause, btn_replay, btn_stop;
    private SeekBar seekBar;
    private VideoView vv_video;
    private boolean isPlaying;

    private Button videoBtn;
    private Button explainAllBtn;
    private Button simulateAnimBtn1, simulateAnimBtn2, simulateAnimBtn3;
    private Button stopBtn1, stopBtn2, stopBtn3;
    private TextView closeLeftBtn, closeRightBtn, closeVideoBtn;
    private LinearLayout jumpToModelBtn, showExplainBtn, showSimulateBtn,controlViewlBtn;
    private LinearLayout leftLayout, rightLayout, videoLayout;

    //三维控制相关
    private WorkspaceConnectionInfo info;
    private WorkspaceType workspaceTypetemp = null;

    private Timer timerRollMax;
    private TimerTask timerTaskRollMax;
    private Handler handlerRollMax;

    private Timer timerRollMin;
    private TimerTask timerTaskRollMin;
    private Handler handlerRollMin;

    private Timer timerPitchMax;
    private TimerTask timerTaskPitchMax;
    private Handler handlerPitchMax;

    private Timer timerPitchMin;
    private TimerTask timerTaskPitchMin;
    private Handler handlerPitchMin;

    private Timer timerPanUp;
    private TimerTask timerTaskPanUp;
    private Handler handlerPanUp;

    private Timer timerPanDown;
    private TimerTask timerTaskPanDown;
    private Handler handlerPanDown;

    private Timer timerPanLeft;
    private TimerTask timerTaskPanLeft;
    private Handler handlerPanLeft;

    private Timer timerPanRight;
    private TimerTask timerTaskPanRight;
    private Handler handlerPanRight;

    private RelativeLayout controlViewLayout,controlMoveLayout;
    private TextView upMoveBtn, downMoveBtn, rightMoveBtn, leftMoveBtn;
    private TextView upViewBtn, downViewBtn, rightViewBtn, leftViewBtn;
    // 离线三维场景数据名称
    String url = "192_168_1_111_8090_iserver_services_realspace-CBD";


    // 三维场景名称
    String sceneName = "CBD";


    private Workspace m_workspace;
    private Scene m_scene;
    private SceneControl mSceneControl;
    // 离线三维场景数据名称
    String workspacePath = "/sdcard/SuperMap/LocalData/ya@xiugai(2)(1)(1)/ya@xiugai(2)(1)(1).sxwu";
    // 三维场景名称
    String mySceneName = "ya@xiugai(2)(1)(1)";

    // 第一次启动的标志量
    boolean firstStart = false;
    // scenecontrol初始化完成消息标志量
    final int SCENECONTROL_INITED = 0;

    boolean isLicenseAvailable = false;
    private final String sdcard = android.os.Environment.getExternalStorageDirectory().getAbsolutePath().toString();


    //    需要申请的权限数组
    protected String[] needPermissions = {
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.ACCESS_FINE_LOCATION,
            Manifest.permission.READ_PHONE_STATE,
            Manifest.permission.ACCESS_WIFI_STATE,
            Manifest.permission.ACCESS_NETWORK_STATE,
            Manifest.permission.CHANGE_WIFI_STATE,
    };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        context = this;
        requestPermissions();  //权限申请
        Environment.setLicensePath(sdcard + "/SuperMap/license/");
        Environment.initialization(this);
        info = new WorkspaceConnectionInfo();
        isLicenseAvailable = isLicenseAvailable();

        //组件功能必须在 Environment 初始化之后才能调用
        setContentView(R.layout.activity_map_acitivty);

        initView();


        setBtn();
        sceneInit();

        playVideo(EXPLAIN_ALL_MP4_PATH);
    }


    private void initView() {


        jumpToModelBtn = findViewById(R.id.jumpToModelBtn);


        explainAllBtn = findViewById(R.id.explainAllBtn);

        showExplainBtn = findViewById(R.id.showExplainBtn);
        showSimulateBtn = findViewById(R.id.showSimulateBtn);
        controlViewlBtn=findViewById(R.id.controlViewlBtn);

        leftLayout = findViewById(R.id.leftLayout);

        rightLayout = findViewById(R.id.rightLayout);
        videoLayout = findViewById(R.id.videoLayout);

        leftLayout.setVisibility(View.GONE);
        rightLayout.setVisibility(View.GONE);
        videoLayout.setVisibility(View.GONE);

        closeRightBtn = findViewById(R.id.closeRightBtn);
        closeLeftBtn = findViewById(R.id.closeLeftBtn);
        closeVideoBtn = findViewById(R.id.closeVideoBtn);

        vv_video = findViewById(R.id.videoView);
        //避免被地图覆盖
        vv_video.setZOrderMediaOverlay(true);

        simulateAnimBtn1 = findViewById(R.id.simulateAnimBtn1);
        simulateAnimBtn2 = findViewById(R.id.simulateAnimBtn2);
        simulateAnimBtn3 = findViewById(R.id.simulateAnimBtn3);

        stopBtn1 = findViewById(R.id.stopBtn1);
        stopBtn2 = findViewById(R.id.stopBtn2);
        stopBtn3 = findViewById(R.id.stopBtn3);

        upMoveBtn = findViewById(R.id.upMoveBtn);
        downMoveBtn = findViewById(R.id.downMoveBtn);
        leftMoveBtn = findViewById(R.id.leftMoveBtn);
        rightMoveBtn = findViewById(R.id.rightMoveBtn);

        upViewBtn = findViewById(R.id.upViewBtn);
        downViewBtn = findViewById(R.id.downViewBtn);
        leftViewBtn = findViewById(R.id.leftViewBtn);
        rightViewBtn = findViewById(R.id.rightViewBtn);

        controlViewLayout=findViewById(R.id.controlViewLayout);
        controlMoveLayout=findViewById(R.id.controlMoveLayout);
    }


    //设置按钮功能
    @SuppressLint("ClickableViewAccessibility")
    private void setBtn() {
        jumpToModelBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {


                if (firstStart) {
                    boolean successed = mSceneControl.getScene().open(mySceneName);
                    if (!successed) {
                        Toast.makeText(context, "跳转场景失败", Toast.LENGTH_LONG);
                    }
                } else {
                    Toast.makeText(context, "场景尚未加载完成", Toast.LENGTH_SHORT).show();
                }

            }
        });

        controlViewlBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                    if(controlMoveLayout.getVisibility()!=View.GONE){
                        controlViewLayout.setVisibility(View.GONE);
                        controlMoveLayout.setVisibility(View.GONE);
                    }else {
                        controlViewLayout.setVisibility(View.VISIBLE);
                        controlMoveLayout.setVisibility(View.VISIBLE);
                    }
            }
        });
        showSimulateBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (leftLayout.getVisibility() != View.GONE) {
                    leftLayout.setVisibility(View.GONE);
                } else {
                    leftLayout.setVisibility(View.VISIBLE);
                    rightLayout.setVisibility(View.GONE);
                }
            }
        });
        showExplainBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (rightLayout.getVisibility() != View.GONE) {
                    rightLayout.setVisibility(View.GONE);
                } else {
                    rightLayout.setVisibility(View.VISIBLE);
                    leftLayout.setVisibility(View.GONE);
                }
            }
        });


        //显示
        explainAllBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                openAndPlay(EXPLAIN_ALL_MP4_PATH);
            }
        });

        closeLeftBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                leftLayout.setVisibility(View.GONE);
            }
        });

        closeRightBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                rightLayout.setVisibility(View.GONE);
            }
        });

        closeVideoBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
 //                if (vv_video != null && vv_video.isPlaying()) {
//                    vv_video.pause();
//
//                }
                vv_video.setZOrderMediaOverlay(false);
                vv_video.clearAnimation();
                stop();
                videoLayout.setVisibility(View.GONE);
                vv_video.setVisibility(View.GONE);
                Log.d(TAG,"执行了隐藏");


            }
        });

        simulateAnimBtn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                openAndPlay(SIMULATE_ANIM_1);
            }
        });

        simulateAnimBtn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                openAndPlay(SIMULATE_ANIM_2);
            }
        });
        simulateAnimBtn3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                openAndPlay(SIMULATE_ANIM_3);
            }
        });

        stopBtn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (vv_video != null && vv_video.isPlaying()) {
                    vv_video.pause();

                }

            }
        });
        stopBtn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (vv_video != null && vv_video.isPlaying()) {
                    vv_video.pause();

                }
            }
        });
        stopBtn3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (vv_video != null && vv_video.isPlaying()) {
                    vv_video.pause();

                }
            }
        });


        //三维控制按钮设置

        upMoveBtn.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent motionEvent) {
                if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {

                    panUpLongTouch(-90);
                    Log.d("debug", "检测到按下");
                } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
                    Log.d("debug", "检测到松开");
                    timerPanUp.cancel();
                }

                return true;
            }
        });

        downMoveBtn.setOnTouchListener(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {

                    panDownLongTouch(90);
                } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {

                    timerPanDown.cancel();
                }

                return true;
            }
        });

        leftMoveBtn.setOnTouchListener(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {

                    panLeftLongTouch(180);
                } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {

                    timerPanLeft.cancel();
                }

                return true;
            }
        });

        rightMoveBtn.setOnTouchListener(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {

                    panRightLongTouch(0);
                } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {

                    timerPanRight.cancel();
                }

                return true;
            }
        });

        upViewBtn.setOnTouchListener(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {

                    pitchMaxLongTouch();
                } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {

                    timerTaskPitchMax.cancel();
                }

                return true;
            }
        });
        downViewBtn.setOnTouchListener(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {

                    pitchMinLongTouch();
                } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {

                    timerPitchMin.cancel();
                }

                return true;
            }
        });
        leftViewBtn.setOnTouchListener(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {

                if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {

                    rollMinLongTouch();
                } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {

                    timerRollMin.cancel();
                }

                return true;
            }
        });
        rightViewBtn.setOnTouchListener(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {

                    rollMaxLongTouch();
                } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {

                    timerRollMax.cancel();
                }

                return true;
            }
        });
    }


    //打开视频页面并播放指定视频或动画
    private void openAndPlay(String videoPath) {

        videoLayout.setVisibility(View.VISIBLE);
        vv_video.setVisibility(View.VISIBLE);
        playVideo(videoPath);
    }


    //场景初始化
    private void sceneInit() {

        mSceneControl = findViewById(R.id.SceneControl);

        mSceneControl.sceneControlInitedComplete(new SceneControl.SceneControlInitedCallBackListenner() {

            @Override
            public void onSuccess(String success) {
                if (!firstStart && isLicenseAvailable) {
                    openLocalScene();
                    firstStart = true;
                }

            }

        });
    }


    // 打开一个本地场景
    private void openLocalScene() {

        // 新建一个工作空间对象
        if (m_workspace == null) {
            m_workspace = new Workspace();
        }
        // 根据工作空间类型，设置服务路径和类型信息。
        workspaceTypetemp = WorkspaceType.SXWU;
        info.setServer(workspacePath);
        info.setType(workspaceTypetemp);
        // 场景关联工作空间
        if (m_workspace.open(info)) {
            m_scene = mSceneControl.getScene();
            m_scene.setWorkspace(m_workspace);
        }
        // 打开场景
        boolean successed = mSceneControl.getScene().open(mySceneName);
        if (successed) {
            Toast.makeText(context, "打开场景成功", Toast.LENGTH_LONG);
        }
    }


    // 判断许可是否可用
    @SuppressLint("ShowToast")
    private boolean isLicenseAvailable() {
        LicenseStatus licenseStatus = Environment.getLicenseStatus();
        if (!licenseStatus.isLicenseExsit()) {
            Toast.makeText(context, "许可不存在，场景打开失败，请加入许可", Toast.LENGTH_LONG).show();
            return false;
        } else if (!licenseStatus.isLicenseValid()) {
            Toast.makeText(context, "许可过期，场景打开失败，请更换有效许可", Toast.LENGTH_LONG).show();
            return false;
        }
        return true;
    }


    //播放视频
    @SuppressLint("ClickableViewAccessibility")
    private void playVideo(String videoPath) {


        vv_video.setZOrderMediaOverlay(true);
        Log.d(TAG, "==========================开始播放视频");
        String path = videoPath;
        File file = new File(path);
        if (!file.exists()) {
            Toast.makeText(context, "视频文件路径错误", Toast.LENGTH_SHORT).show();
            Log.i(TAG, "视频文件路径错误");
            return;
        }


        vv_video.setVideoPath(file.getAbsolutePath());


        Log.i(TAG, "============================开始播放");
        vv_video.start();

        vv_video.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

            @Override
            public void onCompletion(MediaPlayer mp) {
                // 在播放完毕被回调
                playVideo(videoPath);
            }
        });


        vv_video.setOnErrorListener(new MediaPlayer.OnErrorListener() {

            @Override
            public boolean onError(MediaPlayer mp, int what, int extra) {


                Toast.makeText(context, "播放错误", Toast.LENGTH_SHORT).show();
                playVideo(videoPath);

                return false;
            }
        });


    }


    //移动视角相关方法
    @SuppressLint("HandlerLeak")
    public void panUpLongTouch(final double value) {

        timerPanUp = new Timer();

        handlerPanUp = new Handler() {


            public void handleMessage(Message msg) {

                switch (msg.what) {
                    case 0:
                        pan(value + 90);
                        break;

                    default:
                        break;
                }

            }

        };

        timerTaskPanUp = new TimerTask() {

            @Override
            public void run() {

                handlerPanUp.sendEmptyMessage(0);

            }
        };
        timerPanUp.schedule(timerTaskPanUp, 10, 10);
    }

    @SuppressLint("HandlerLeak")
    public void panDownLongTouch(final double value) {

        timerPanDown = new Timer();

        handlerPanDown = new Handler() {

            public void handleMessage(Message msg) {

                switch (msg.what) {
                    case 0:
                        pan(value + 90);
                        break;

                    default:
                        break;
                }

            }

        };

        timerTaskPanDown = new TimerTask() {

            @Override
            public void run() {

                handlerPanDown.sendEmptyMessage(0);

            }
        };
        timerPanDown.schedule(timerTaskPanDown, 10, 10);
    }

    @SuppressLint("HandlerLeak")
    public void panLeftLongTouch(final double value) {

        timerPanLeft = new Timer();

        handlerPanLeft = new Handler() {

            public void handleMessage(Message msg) {

                switch (msg.what) {
                    case 0:
                        pan(value + 90);
                        break;

                    default:
                        break;
                }

            }

        };

        timerTaskPanLeft = new TimerTask() {

            @Override
            public void run() {

                handlerPanLeft.sendEmptyMessage(0);

            }
        };
        timerPanLeft.schedule(timerTaskPanLeft, 10, 10);
    }

    @SuppressLint("HandlerLeak")
    public void panRightLongTouch(final double value) {

        timerPanRight = new Timer();

        handlerPanRight = new Handler() {

            public void handleMessage(Message msg) {

                switch (msg.what) {
                    case 0:
                        pan(value + 90);
                        break;

                    default:
                        break;
                }

            }

        };

        timerTaskPanRight = new TimerTask() {

            @Override
            public void run() {

                handlerPanRight.sendEmptyMessage(0);

            }
        };
        timerPanRight.schedule(timerTaskPanRight, 10, 10);
    }


    // 旋转按钮长按事件
    @SuppressLint("HandlerLeak")
    public void rollMaxLongTouch() {

        timerRollMax = new Timer();

        handlerRollMax = new Handler() {

            public void handleMessage(Message msg) {

                switch (msg.what) {
                    case 0:
                        mSceneControl.getScene().setRollEye(0.25);
                        break;

                    default:
                        break;
                }

            }

        };

        timerTaskRollMax = new TimerTask() {

            @Override
            public void run() {

                handlerRollMax.sendEmptyMessage(0);

            }
        };

        timerRollMax.schedule(timerTaskRollMax, 10, 10);
    }

    // 旋转按钮长按事件
    @SuppressLint("HandlerLeak")
    public void rollMinLongTouch() {

        timerRollMin = new Timer();

        handlerRollMin = new Handler() {

            public void handleMessage(Message msg) {

                switch (msg.what) {
                    case 0:
                        mSceneControl.getScene().setRollEye(-0.25);
                        break;

                    default:
                        break;
                }

            }

        };

        timerTaskRollMin = new TimerTask() {

            @Override
            public void run() {

                handlerRollMin.sendEmptyMessage(0);

            }
        };

        timerRollMin.schedule(timerTaskRollMin, 10, 10);
    }

    // 俯仰按钮长按事件
    @SuppressLint("HandlerLeak")
    public void pitchMinLongTouch() {

        timerPitchMin = new Timer();

        handlerPitchMin = new Handler() {

            public void handleMessage(Message msg) {

                switch (msg.what) {
                    case 0:
                        mSceneControl.getScene().setPitch(-0.25);
                        break;

                    default:
                        break;
                }

            }

        };

        timerTaskPitchMin = new TimerTask() {

            @Override
            public void run() {

                handlerPitchMin.sendEmptyMessage(0);

            }
        };

        timerPitchMin.schedule(timerTaskPitchMin, 10, 10);
    }

    // 俯仰长按事件
    @SuppressLint("HandlerLeak")
    public void pitchMaxLongTouch() {

        timerPitchMax = new Timer();

        handlerPitchMax = new Handler() {

            public void handleMessage(Message msg) {

                switch (msg.what) {
                    case 0:
                        mSceneControl.getScene().setPitch(0.25);
                        break;

                    default:
                        break;
                }

            }

        };

        timerTaskPitchMax = new TimerTask() {

            @Override
            public void run() {

                handlerPitchMax.sendEmptyMessage(0);

            }
        };

        timerPitchMax.schedule(timerTaskPitchMax, 10, 10);
    }

    public void pan(double angle) {
        double l = 0.00001;
        double heading = mSceneControl.getScene().getCamera().getHeading();
        double longla = l * Math.sin((heading + angle) * Math.PI / 180);
        double lan = l * Math.cos((heading + angle) * Math.PI / 180);
        mSceneControl.getScene().pan(longla, lan);
    }


    /**
     * 重新开始播放
     */
    protected void replay() {
        if (vv_video != null && vv_video.isPlaying()) {
            vv_video.seekTo(0);
            Toast.makeText(this, "重新播放", Toast.LENGTH_SHORT).show();
            btn_pause.setText("暂停");
            return;
        }
        isPlaying = false;

    }

    /**
     * 暂停或继续
     */
    protected void pause() {
        if (btn_pause.getText().toString().trim().equals("继续")) {
            btn_pause.setText("暂停");
            vv_video.start();
            Toast.makeText(this, "继续播放", Toast.LENGTH_SHORT).show();
            return;
        }
        if (vv_video != null && vv_video.isPlaying()) {
            vv_video.pause();
            btn_pause.setText("继续");
            Toast.makeText(this, "暂停播放", Toast.LENGTH_SHORT).show();
        }
    }

    /*
     * 停止播放
     */
    protected void stop() {
        if (vv_video != null && vv_video.isPlaying()) {
            vv_video.stopPlayback();
             isPlaying = false;
        }
    }


    //移动到合适的视角
    private  void  moveView(){

    }

    /**
     * 检测权限
     * return true:已经获取权限
     * return false: 未获取权限，主动请求权限
     */

    public boolean checkPermissions(String[] permissions) {
        return EasyPermissions.hasPermissions(this, permissions);
    }

    /**
     * 申请动态权限
     */
    private void requestPermissions() {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
            return;
        }
        if (!checkPermissions(needPermissions)) {
            EasyPermissions.requestPermissions(
                    this,
                    "为了应用的正常使用，请允许以下权限。",
                    0,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE,
                    Manifest.permission.ACCESS_FINE_LOCATION,
                    Manifest.permission.READ_PHONE_STATE,
                    Manifest.permission.ACCESS_WIFI_STATE,
                    Manifest.permission.ACCESS_NETWORK_STATE,
                    Manifest.permission.CHANGE_WIFI_STATE);
            //没有授权，编写申请权限代码
        } else {
            //已经授权，执行操作代码
        }
    }



    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        // Forward results to EasyPermissions
        EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
    }

}